package com.jinghua.treatment.service.impl;

import com.jinghua.treatment.entity.SysInquiry;
import com.jinghua.treatment.entity.SysInquiryExample;
import com.jinghua.treatment.mapper.SysInquiryMapper;
import com.jinghua.treatment.service.SysInquiryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 问诊单业务接口实现类
 * Created by 王兴光 on 2018/6/13.
 */
@Service
public class SysInquiryServiceImpl implements SysInquiryService{
    @Resource
    private SysInquiryMapper inquiryMapper;

    @Override
    @Transactional
    public int addInquiry(SysInquiry inquiry) {
        int result = -1;
        try {
            if(inquiry!=null){
                result = inquiryMapper.insertSelective(inquiry);
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return result;
    }

    @Override
    public SysInquiry selectById(String uuid) {
        return inquiryMapper.selectByPrimaryKey(uuid);
    }

    @Override
    public List<SysInquiry> selectByDoctorId(Integer doctorId) {
        List<SysInquiry> inquiryList = null;
        try {
            SysInquiryExample example = new SysInquiryExample();
            SysInquiryExample.Criteria criteria = example.createCriteria();
            if(doctorId!=null) {
                example.getOredCriteria().add(criteria.andDoctorIdEqualTo(doctorId));
            }
            inquiryList = inquiryMapper.selectByExample(example);
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return inquiryList;
    }

    @Override
    public List<SysInquiry> selectByPatientId(Integer patientId) {
        List<SysInquiry> inquiryList = null;
        try {
            SysInquiryExample example = new SysInquiryExample();
            SysInquiryExample.Criteria criteria = example.createCriteria();
            if(patientId!=null) {
                example.getOredCriteria().add(criteria.andPatientIdEqualTo(patientId));
            }
            inquiryList = inquiryMapper.selectByExample(example);
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return inquiryList;
    }
}
